package com.hwj.controller;

import com.hwj.service.PetScienceService;
import com.hwj.utils.JsonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/science")
@Slf4j
public class PetScienceController {
    @Autowired
    PetScienceService petScienceService;

    /**
     * 根据类型查询相关百科
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("getByType")
    public JsonResponse getByType(String type,Integer pageNum,Integer pageSize){
        return JsonResponse.successResponse(0,"查询相关百科成功",petScienceService.getByType(type,pageNum,pageSize));
    }

    @GetMapping("getById")
    public JsonResponse getById(@RequestParam Long id){
        return JsonResponse.successResponse(0,"查询百科详情成功",petScienceService.getById(id));
    }

    /**
     * 根据标签模糊查询相关百科
     * @param tag
     * @return
     */
    @GetMapping("getByTag")
    public JsonResponse getByTag(@RequestParam String tag){
        return JsonResponse.successResponse(0,"查询相关百科成功",petScienceService.getByTag(tag));
    }

    /**
     * 分页查询相关百科
     * @param name
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("listByPage")
    public JsonResponse listByPage(String name,String type,Integer pageNum,Integer pageSize){
        return JsonResponse.successResponse(0,"分页查询百科成功",petScienceService.listByPage( name, type, pageNum, pageSize));
    }
}
